<template>
	<view>
		<view class="header">
			<cu-custom bgColor="bg-white" :isBack="true">
				<block slot="content">
					{{start}} <text class=" myIcon-jiantou padding-lr-xs"></text> {{end}}
				</block>
			</cu-custom>
			<!--前一天后一天-->
			<view class="cu-bar bg-white top-line min-height35">
				<view class="action" @click="jianDay">
					<text class="cuIcon-back text-gray"></text> 前一天
				</view>
				<view style=" background-color: #ffdf40; border-radius: 8upx;">
					<picker mode="date" :value="date" :start="startTime" end="2025-12-30" @change="DateChange"
						style="padding-right: 0px">
						<view class="flex align-center">
							<view style="margin: 8upx">{{date}} </view>
							<view
								style="height: 22px; max-height: 22px border-left: 1px; border-right-style: solid; transform: scaleX(.333)">
							</view>
							<view style="margin: 8upx" class="cuIcon-calendar"></view>
						</view>
					</picker>
				</view>
				<view class="action" @click="jiaDay">
					后一天 <text class="cuIcon-right text-gray"></text>
				</view>
			</view>
		</view>
		<view class="" style="height: 140rpx;"></view>
		<view class="bg-white" style="margin-top: 3px" v-for="(item,index) in dataList" :key="index" v-if="dataList.length!=0" @click="goSearchItem(item.id)">
			<view class="padding-lr-sm padding-tb-xs">
				<view class="flex justify-between">
					<view class="flex align-center">
						<view class="font-size21" style="color: #3d3d3d">{{item.departure_time}}</view>
					</view>

					<view class="flex align-center">
						<img width="20px" height="20px" mode="widthFix" src="/static/bus.png" />
						{{item.car_type}}
					</view>

					<view class="flex align-center text-right">
						<view style="width: 100%">
							<view>
								<text class="text-orange2 font-size12 padding-lr-xs">¥</text>
								<text class="font-size20 text-orange2">{{item.price}}</text>
							</view>
							<view class="font-size13 text-gray" style="margin:10rpx 0">{{item.total_count}}张</view>
							<view class="font-size13 text-gray">{{item.time_remark}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		<view class="zanwu" v-if="dataList.length==0">
			<image src="../../../static/noCart.png" mode=""></image>
			<view>暂无车次</view>
		</view>
	</view>
</template>

<script>
	export default {
		name: "SearchList",
		data() {
			return {
				date: '2018-12-25',
				station: ['北京', '唐山'],
				scrollTopFlag: 0,
				showCond: '',
				modalName: '',
				// 筛选的tab
				tabCur: 0,
				
				cond2Checkbox: [{
					value: 'A',
					checked: true
				}, {
					value: 'B',
					checked: true
				}, {
					value: 'C',
					checked: false
				}],
				// 筛选条件
				end: '',
				start: '',
				page: 1,
				dataList: [],
				startTime:''
			}
		},
		onLoad(e) {
			let that = this
			that.date = e.time
			that.start = e.start
			that.end = e.end
			var now = new Date();
			var year = now.getFullYear(); //获取完整的年份(4位,1970-????)
			var month = now.getMonth() + 1; //获取当前月份(0-11,0代表1月)
			var day = now.getDate(); //获取当前日(1-31)
			var timeStr = year + "-" + (month<10?"0"+month:month) + "-" + (day<10?"0"+day:day) ;
			that.startTime = timeStr
		},
		onShow() {
			this.page = 1
			this.dataList = []
			this.getList()
		},
		onReachBottom() {
			this.page++
			this.getList()
		},
		methods: {
			DateChange(e) {
				this.date = e.detail.value
				this.page=1
				this.dataList = []
				this.getList()
			},
			// 隐藏modal
			hideModal(e) {
				this.modalName = null
			},
			// 显示某个modal
			showModal(modalName) {
				this.modalName = modalName
			},
			selCondTab(index) {
				this.tabCur = index
			},
			jianDay(){
				var date = new Date(this.date); // 指定日期，可以根据具体需求修改
				var timestamp = date.getTime()
				const dates = new Date(timestamp - 24*60*60*1000);
				const year = dates.getFullYear();
				const month = String(dates.getMonth() + 1).padStart(2, '0');
				const day = String(dates.getDate()).padStart(2, '0');
				const formattedDate = `${year}-${month}-${day}`;
				this.date = formattedDate
				this.page=1
				this.dataList = []
				this.getList()
			},
			jiaDay(){
				var date = new Date(this.date); // 指定日期，可以根据具体需求修改
				var timestamp = date.getTime()
				const dates = new Date(timestamp + 24*60*60*1000);
				const year = dates.getFullYear();
				const month = String(dates.getMonth() + 1).padStart(2, '0');
				const day = String(dates.getDate()).padStart(2, '0');
				const formattedDate = `${year}-${month}-${day}`;
				this.date = formattedDate
				this.page=1
				this.dataList = []
				this.getList()
			},
			getList() {
				let that = this
				that.tui.request("api.ticket/ticket_list", "POST", {
					start_address: that.start,
					end_address: that.end,
					train_number_time: that.date,
					page: that.page
				}, false, false, false).then((res) => {
					if (res.code == 1) {
						that.dataList = that.dataList.concat(res.data.list)
					}
				}).catch((res) => {

				})
			},
			goSearchItem(e) {
			    uni.navigateTo({
			        url: "/pages/home/orderDetail/OrderDetail?id="+e
			    })
			}
		},

	}
</script>

<style scoped>
	.hide-cond {
		transition-duration: 0.5s;
		bottom: -1000px;
	}

	.show-cond {
		transition-duration: 0.5s;
		bottom: 0px;
	}

	.scroll {
		overflow-y: auto;
		/*position: absolute;*/
		width: 100%;
	}

	.dian {
		width: 8px;
		height: 8px;
		border-radius: 100%;
		background-color: #ffdf40;
	}

	.header {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
	}
</style>